<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/pub/head_bootstrap.inc"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=7" />

<title>${module.moduleName}-编辑</title>
</head>
<body>
	<div class="FrameWindowBg"></div>
	<%@ include file="/WEB-INF/jsp/module/view/bootstrap/part/edit.jsp" %>
	<%@ include file="/WEB-INF/jsp/module/view/bootstrap/part/form.jsp" %>
	<%@ include file="/WEB-INF/jsp/module/view/bootstrap/part/list.jsp" %>
	<%@ include file="/WEB-INF/jsp/module/view/bootstrap/part/view.jsp" %>
	<script>
		$(function(){
			$.sdModule.edit.init({
				menuId:'${param.menuId}',
				forWindow:true,
				parentElement:$(".FrameWindowBg"),
		 		main:{
		 			id:'${id}',
			 		mdId:'${module.moduleId}',
			 		mdCode:'${module.module}',
			 		mdName:'${module.moduleName}',
			 		fields:'${module.moduleFields}',
			 		editJS:'${module.editedJs}',
			 		dicObj:'${module.dic}',
			 		columns:2,
			 		beforeRender:function(){},
			 		afterRender:function(data){
			 			<c:if test="${param.editParams!=null}">
			 				var editParams = JSON.parse('${param.editParams}'||'[]');
			 				for(var key in editParams){
			 					if(editParams[key].indexOf("encodeURIComponent_") != -1){
			 						editParams[key] = decodeURIComponent(decodeURIComponent(editParams[key])).replace("encodeURIComponent_","");
			 					}
			 					$("input[name='"+key+"']").val(editParams[key]);
			 				}
			 			</c:if>
					},
			 		showTab:1,
					showType:0
		 		},
		 		getTabs:function(){
		 			var tabs = [];
		 			if(typeof tabRender =="undefined"){
		 				tabRender = {};
		 			}
		 			<c:if test="${fn:length(module.childTab)>0}"> 
		 			<c:forEach var="o" items="${module.childTab}">
		 				<c:if test="${module.module != 'familyPersons'}">
		 				tabs.push($.extend({
		 					mdId:'${o.moduleId}',
		 			 		mdCode:'${o.module}',
		 					mdName:'${o.moduleName}',
		 					menuId:'edit${module.module}',
		 					relationField:'${o.relationField}',
		 					editModule:'${o.editModule}',
		 					showTab:'${o.showTab}',
		 					<c:if test="${o.showType == 0 && id==null}">
		 					showType:2,
		 					</c:if>
		 					<c:if test="${o.showType != 0 || id!=null}">
		 					showType:'${o.showType}',
		 					</c:if>
		 					columns:2,
		 					<c:if test="${o.editModule != 1}">
		 					defaultSearchParam:function(){
		 						var value = '';
		 						<c:if test="${id!=null}">
		 						var data = $.sdModule.edit.params.tabInstance['${module.module}'].formParams.data;
		 						value = data['${o.entityField}'].value;
		 						</c:if>
		 						return JSON.stringify([{name:'${o.relationField}',value:value,type:"exact-match"}]);
		 					},
		 					</c:if>
		 					afterRender:function(data){
		 						$("input[name='"+$.sdModule.camelCase('${o.relationField}')+"']",$("#form${o.module}")).val('${id}');
					 		},
		 					<c:if test="${o.showType == 1 && id==null}">
		 					hasToolbar:false,
		 					</c:if>
		 					<c:if test='${o.showType == 1 && id!=null}'>
		 					toolbarParams:{
		 						//默认查看页或者编辑页的列表打开以弹框的形式打开
		 						buttons:[{id:"add",params:{dialog:true,editParams:{'${o.relationEntityField}':'${id}'}}},
		 							   	 {id:"modify",params:{dialog:true}<c:if test="${o.editModule == 1}">,isHide:true</c:if>},
		 							   	 {id:"delete"}
		 							   	 ]
		 					},
		 					linkOptions:{
		 						linkValue:'${id}',
		 						linkMdId:'${module.moduleId}'
		 					}
		 					</c:if>
		 					},tabRender['${o.module}']));
		 				</c:if>
		 			</c:forEach>
		 			</c:if>
		 			return tabs;
		 		},
		 		buttons:[
	 			    {id:"save",name:"保存",className:"btn-blue",onclick:function(){
	 			    	FF_Save(false);
	 		 		}},
	 		 		{id:"cancel",name:"关闭",className:"btn-white",onclick:function(){
	 					window.parent.LG.closeCurrentTab();
	 		 		}}
	 	 		]
			});
		})
		
		
		function FF_Save(isNew){
			var tabId = null;
	    	try{
	    		tabId = $(".nav-tabs>li.active").find("a").attr("href").replace("#","");
	    		if($("#form"+tabId).length == 0){
	    			tabId = '${module.module}';
	    		}
	    	}catch(e){
	    		tabId = '${module.module}';
	    	}
	    	
	    	$("#form"+tabId).attr("action","${baseURL}/jdbc/common/basecommonsave/saveIncludeFile.do?mdCode="+tabId);
			BT.submitForm($("#form"+tabId), function (data) {
				if (data && data.hasOk) {
					if(isNew){
						window.location.href = "${baseURL}/jdbc/common/basecommonedit/toEdit.do?mdCode=${module.module}";
					}else{
						if($.sdModule.edit.params.tab && $.sdModule.edit.params.tab.length>0){
							var id = null;
							if(tabId == '${module.module}'){
								id = data.bean.id;
							}else{
								id = '${id}'
							}
							window.location.href = "${baseURL}/jdbc/common/basecommonedit/toEdit.do?mdCode=${module.module}&id="+id;
						}else{
							BT.showSuccess('操作成功!',function(){
								// 关闭窗口 刷新父窗口
							    win.LG.closeAndReloadParent(null, "${param.menuId}", tabId);
							});
						}
					}
	            } else { 
	            	BT.showError("操作失败!失败信息如下:\n" + data.message + "\n如您对以上信息有疑问，请联系管理人员!");
	            }
			});
		}
		
		function FF_Reload(tab){
			$.sdModule.edit.params.tabInstance[tab].refreshTable();
		}
		
		function getBirthdayFromIdCard(idCard) {  
	        var birthday = "";  
	        if(idCard != null && idCard != ""){  
	            if(idCard.length == 15){  
	                birthday = "19"+idCard.substr(6,6);  
	            } else if(idCard.length == 18){  
	                birthday = idCard.substr(6,8);  
	            }  
	          
	            birthday = birthday.replace(/(.{4})(.{2})/,"$1-$2-");  
	        }  
	        return birthday;  
	   }
	</script>
</body>
</html>